package com.liang.five_Fanout_Exchanges;

import com.rabbitmq.client.Channel;
import utils.RabbitmqUtil;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.Scanner;
import java.util.concurrent.TimeoutException;

/**
 * Created with IntelliJ IDEA.
 * User: XIAOLIANG
 * Date: 2021/6/18
 * Time: 16:54
 * Description: 发布/订阅 (fanout) 交换机
 *
 * 生产者
 *
 */
public class EmitLog {

    public static final String EXCHANGES_NAME  =  "logs";


    public static void main(String[] args) throws IOException, TimeoutException {


        /**
         *
         *
         */

        Channel channel = RabbitmqUtil.getChannel();

        channel.exchangeDeclare(EXCHANGES_NAME,"fanout");

        Scanner scanner = new Scanner(System.in);

        while (scanner.hasNext()){

            String log = scanner.nextLine();

            channel.basicPublish(EXCHANGES_NAME,"",null,log.getBytes(StandardCharsets.UTF_8));


        }



    }


}